package com.lucifer;

import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * 测试LinkedHashMap
 *
 * @Author yuxiao05@meituan.com
 * @Create 2016-07-07 下午4:18
 */

public class TestLinkedHashMap {
  public static void main(String[] args){
    test2();
  }

  public static void test1() {
    LinkedHashMap<Integer, String> map = new LinkedHashMap<>();

    map.put(1, "aaaa");
    map.put(2, "bbbb");
    map.put(7, "kkkk");
    map.put(3, "cccc");
    map.put(4, "dddd");
    map.put(5, "eeee");

    Iterator<Map.Entry<Integer, String>> iter =
            map.entrySet().iterator();

    while (iter.hasNext()) {
      System.out.println(iter.next().getValue());
    }
  }

  public static void test2() {
    LinkedHashMap<Integer, String> map = new LinkedHashMap<>(16, 0.75f, true);

    map.put(1, "aaaa");
    map.put(2, "bbbb");
    map.put(7, "kkkk");
    map.put(3, "cccc");
    map.put(4, "dddd");
    map.put(5, "eeee");

    map.get(3);
    map.get(7);

    for (Map.Entry<Integer, String> entry : map.entrySet()) {
      System.out.println(entry.getValue());
    }
  }

  public static void test3() {
    HashMap<Integer, String> map = new HashMap<>();

    map.put(1, "aaaa");
    map.put(2, "bbbb");
    map.put(7, "kkkk");
    map.put(3, "cccc");
    map.put(4, "dddd");
    map.put(5, "eeee");

    for (Map.Entry<Integer, String> entry : map.entrySet()) {
      System.out.println(entry.getValue());
    }
  }
}
